package com.ash.controller.order;

import com.ash.domain.vo.OrderDetailVo;
import com.ash.service.order.OrderService;
import com.ash.util.JsonUtil;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : Chen Chao
 * @encoding : UTF-8
 * @date : 2021/3/22 17:28
 * @file : project06.com.ash.controller.order.OrderController.java
 * @software : IntelliJ IDEA
 * @since : 1.8
 */
@Controller
public class OrderController {
    @Resource
    OrderService orderService;
    @RequestMapping("/user/order")
    public String order(){
        return "/user/order";
    }
    @RequestMapping("/user/order/selectAll")
    @ResponseBody
    public String selectAll(@Nullable @RequestParam("uid")Integer uid,
                            @Nullable @RequestParam("page") Integer page,
                            @Nullable @RequestParam("limit") Integer limit,
                            @Nullable @RequestParam("order") String order){
        return JsonUtil.getJsonList(orderService.dataCount(uid),orderService.selectByUid(uid,page,limit));
    }
    @RequestMapping("/user/order/orderDetailSelect")
    public String orderDetail(Model model,@RequestParam("oid")Integer oid){
        model.addAttribute("oid",oid);
        return "user/orderDetail";
    }
    @RequestMapping("/user/order/orderDetailSelectList")
    @ResponseBody
    public String orderDetailSelect(@Nullable @RequestParam("oid")Integer oid){
        List<OrderDetailVo> orderDetailVos = orderService.selectDetailByOid(oid);
        return JsonUtil.getJsonList(orderDetailVos.size(),orderDetailVos);
    }
}
